<template>
  <div>
    <el-form ref="form" :model="project_from" label-width="130px">
      <el-form-item label="项目名称">
        <el-input v-model="project_from.project_name"></el-input>
      </el-form-item>
      <el-form-item label="git仓库地址">
        <el-input v-model="project_from.git_url"></el-input>
      </el-form-item>
      <el-form-item label="git用户名">
        <el-input v-model="project_from.git_user"></el-input>
      </el-form-item>
      <el-form-item label="git密码">
        <el-input type="password" v-model="project_from.git_password"></el-input>
      </el-form-item>
      <el-form-item label="代码分支">
        <el-select v-model="project_from.branch" placeholder="请选择">
          <el-option
              v-for="item in branch_list"
              :key="item"
              :label="item"
              :value="item">
          </el-option>
        </el-select>
        <el-button type="success" @click="get_branch_list">获取分支</el-button>
      </el-form-item>
      <el-form-item label="部署方式">
        <el-select v-model="project_from.deployment_way" placeholder="请选择">
          <el-option
              v-for="item in deployment_way"
              :key="item.value"
              :label="item.label"
              :value="item.value">
          </el-option>
        </el-select>

        <!--        <el-input v-model="project_from.deployment_way"></el-input>-->
      </el-form-item>
      <el-form-item label="关联小程序">
        <el-select v-model="project_from.appid" placeholder="请选择">
          <el-option
              v-for="item in app_list"
              :key="item.appid"
              :label="item.name"
              :value="item.appid">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="编译前执行的命令">
        <el-input v-model="project_from.perform_before"></el-input>
      </el-form-item>
      <el-form-item label="编译命令">
        <el-input v-model="project_from.compile_command"></el-input>
      </el-form-item>
      <el-form-item label="编译路径">
        <el-input v-model="project_from.build_path"></el-input>
      </el-form-item>
      <el-form-item label="是否使用es6">
        <el-select v-model="project_from.is_es_6" placeholder="请选择">
          <el-option
              v-for="item in is_es_6"
              :key="item.value"
              :label="item.label"
              :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="create_project_submit">确 定</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import {GetWxAppAll, GetBranchList} from "@/request/api";

export default {
  name: "CreateProject",
  created() {
    this.get_app_list();
  },
  data() {
    return {
      project_from: {
        project_name: "",
        git_url: "",
        branch: "",
        deployment_way: "自动",
        token: "",
        appid: "",
        git_user: "",
        git_password: "",
        perform_before: "",
        git_path: "",
        compile_command: "",
        build_path: "",
        is_es_6: "",
      },
      branch_list: [],
      is_es_6: [
        {
          label: "是",
          value: "true"
        },
        {
          label: "否",
          value: "false"
        }
      ],
      app_list: [],
      deployment_way: [
        {
          label: "自动",
          value: "自动"
        },
        {
          label: "手动",
          value: "手动"
        }
      ]
    }
  },
  methods: {

    create_project_submit() {
      this.$emit("create_project_submit", this.project_from)
    },
    get_app_list() {
      GetWxAppAll({}).then(res => {
        if (res.code == 200) {
          this.app_list = res.data;
        } else {
          this.$message.error(res.msg);
        }
        console.log(res)
      })
    },
    get_branch_list() {
      let data = {
        git_url: this.project_from.git_url,
        git_user: this.project_from.git_user,
        git_password: this.project_from.git_password
      }
      GetBranchList(data).then(res => {
        if (res.code == 200) {
          this.branch_list = res.data;
          this.$message.success("获取分支成功");
        } else {
          this.$message.error(res.msg);
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
